package com.example.demo.thread.state;

/**
 * @Author: liull
 * @Description:
 * @Date: Created in 14:12 2020/5/29
 * @Modified By:
 */
public class MyThread3 extends Thread {
    private static MyThread3 thread3 = new MyThread3();
    private  MyThread3 thread = new MyThread3();

    private Object lock = new Object();

    private static Object _lock = new Object();

    @Override
    public void run() {
        // 没有加static 对象锁，不同对象两个线程调用同一个方法 不会产生互斥
        //        doSomething();
        // 同一个对象两个线程调用同一个方法 会产生互斥
        thread3.doSomething();
        // 同步方法加static 表示是类级别锁 .class同一个类唯一
    }

    private void doSomething() {
        synchronized (lock) {
            while (true) {

            }
        }

    }
}
